import { defineStore } from 'pinia'
import storage from '@/utils/storage'

export const useUserStore = defineStore('userStore', {
    state: () => {
        return {
            tokenInfo: storage.get('shop_store') || {},
        }
    },
    actions: {
        ADD_TOKEN(payload: { access_token: string; refresh_token: string; shopAssistantPhone: string }) {
            this.tokenInfo = payload
            storage.set('shop_store', payload)
        },
        REMOVE_TOKEN() {
            this.tokenInfo = { access_token: '', refresh_token: '' }
            storage.set('shop_store', { access_token: '', refresh_token: '', shopAssistantPhone: '' })
        },
    },
    getters: {
        token: (state) => {
            return state?.tokenInfo?.access_token
        },
        shopAssistantPhone: (state) => {
            return state?.tokenInfo?.shopAssistantPhone
        },
    },
})
